package day08;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Scanner;

public class Demo07 {

	public static void main(String[] args) throws Exception {

		String file = "abc/letter.txt";
		FileInputStream fis=new FileInputStream(file);
		BufferedInputStream bis=new BufferedInputStream(fis);
		InputStreamReader isr=new InputStreamReader(bis,"utf-8");
		
		BufferedReader in=new BufferedReader(isr);
		
		String str;
		while((str=in.readLine())!=null){
			System.out.println(str);
		}
		in.close();
		
		
		
		Scanner scan = new Scanner(System.in);
		FileOutputStream fos = new FileOutputStream(file, true);
		//-----true,可以保证FileOutputStream,下次输入的时候，
		//在上次写的位置继续写，不会覆盖已经编辑的文档。
		BufferedOutputStream bos = new BufferedOutputStream(fos);
		OutputStreamWriter osw = new OutputStreamWriter(bos, "UTF-8");

		PrintWriter out = new PrintWriter(osw, true);
		
		System.out.println("请写入内容！");
		while (true) {

			String input = scan.nextLine();
			if (input.toUpperCase().equals("EXIT")) {
				System.out.println("编写结束！");
				break;
			}
			out.println(input);

		}
		
		out.close();

	}

}
